﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Camc.Quality.Migrations
{
    public partial class add_rnode : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.RenameColumn(
                name: "ConfirmResult_DisplayName",
                table: "RMeasuredResultEntity",
                newName: "FirstConfirmResult_DisplayName");

            migrationBuilder.RenameColumn(
                name: "ConfirmResult",
                table: "RMeasuredResultEntity",
                newName: "FirstConfirmResult");

            migrationBuilder.AddColumn<DateTime>(
                name: "ExportDate",
                table: "BopNodes",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "RelationDate",
                table: "BopNodes",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "RbopDescs",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    Model = table.Column<string>(nullable: true),
                    ModelName = table.Column<string>(nullable: true),
                    LotNo = table.Column<string>(nullable: true),
                    DrawingNo = table.Column<string>(nullable: true),
                    StageSign = table.Column<string>(nullable: true),
                    Status = table.Column<int>(nullable: false),
                    Property = table.Column<int>(nullable: false),
                    IsUsed = table.Column<int>(nullable: false),
                    ReleaseTime = table.Column<DateTime>(nullable: true),
                    ReleaseUserId = table.Column<long>(nullable: true),
                    QualityStatus = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RbopDescs", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "RbopNodes",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    RbopDescId = table.Column<Guid>(nullable: false),
                    ParentId = table.Column<Guid>(nullable: false),
                    NodeDrawingNo = table.Column<string>(nullable: true),
                    NodeName = table.Column<string>(nullable: true),
                    NodeType = table.Column<int>(nullable: false),
                    Sort = table.Column<int>(nullable: false),
                    NodeLevel = table.Column<int>(nullable: false),
                    ProcessCode = table.Column<string>(nullable: true),
                    IsLeaf = table.Column<int>(nullable: false),
                    ParentCode = table.Column<string>(nullable: true),
                    NodeCode = table.Column<string>(nullable: true),
                    IsExport = table.Column<int>(nullable: false),
                    PadId = table.Column<string>(nullable: true),
                    PadName = table.Column<string>(nullable: true),
                    RtechniqueEntityId = table.Column<Guid>(nullable: true),
                    IsReturn = table.Column<int>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RbopNodes", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RbopNodes_RbopDescs_RbopDescId",
                        column: x => x.RbopDescId,
                        principalTable: "RbopDescs",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "RbopContents",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorUserId = table.Column<long>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierUserId = table.Column<long>(nullable: true),
                    IsDeleted = table.Column<bool>(nullable: false),
                    DeleterUserId = table.Column<long>(nullable: true),
                    DeletionTime = table.Column<DateTime>(nullable: true),
                    RbopNodeId = table.Column<Guid>(nullable: false),
                    Remark = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RbopContents", x => x.Id);
                    table.ForeignKey(
                        name: "FK_RbopContents_RbopNodes_RbopNodeId",
                        column: x => x.RbopNodeId,
                        principalTable: "RbopNodes",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_RbopContents_RbopNodeId",
                table: "RbopContents",
                column: "RbopNodeId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_RbopNodes_RbopDescId",
                table: "RbopNodes",
                column: "RbopDescId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "RbopContents");

            migrationBuilder.DropTable(
                name: "RbopNodes");

            migrationBuilder.DropTable(
                name: "RbopDescs");

            migrationBuilder.DropColumn(
                name: "ExportDate",
                table: "BopNodes");

            migrationBuilder.DropColumn(
                name: "RelationDate",
                table: "BopNodes");

            migrationBuilder.RenameColumn(
                name: "FirstConfirmResult_DisplayName",
                table: "RMeasuredResultEntity",
                newName: "ConfirmResult_DisplayName");

            migrationBuilder.RenameColumn(
                name: "FirstConfirmResult",
                table: "RMeasuredResultEntity",
                newName: "ConfirmResult");
        }
    }
}
